package com.mcxx.util;



import cn.hutool.extra.qrcode.QrCodeUtil;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import com.mcxx.modules.system.dto.AuditConfirmListDTO;
import com.mcxx.modules.system.dto.ConfirmListMemberDTO;
import com.mcxx.modules.system.dto.PdfApproveDTO;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;


public class PdfTempUtil {











    public static class DataUtil {

        public static String[] separatePath(String path) {
            if (path == null || "".equals(path.trim())) {
                return null;
            }
            String[] sep = path.split("\\.");
            return new String[]{sep[0], sep[1]};
        }
    }


    public static String createPDF(String toPath, String pdfName, String suffFixName, PdfApproveDTO pdf) throws Exception {

        String outPath = toPath + pdfName + suffFixName;

        Rectangle rect = new Rectangle(PageSize.A4);

        Document doc = new Document(rect);

        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

        Font textFont = new Font(bfChinese, 11, Font.NORMAL);
        Font redTextFont = new Font(bfChinese, 11, Font.NORMAL);
        Font boldFont = new Font(bfChinese, 11, Font.BOLD);
        Font redBoldFont = new Font(bfChinese, 11, Font.BOLD);
        Font firsetTitleFont = new Font(bfChinese, 22, Font.BOLD);
        Font secondTitleFont = new Font(bfChinese, 15, Font.BOLD);
        Font underlineFont = new Font(bfChinese, 11, Font.UNDERLINE);

        PdfWriter.getInstance(doc, new FileOutputStream(new File(outPath)));

        doc.open();

        doc.newPage();

        Paragraph p1 = new Paragraph();

        Phrase ph1 = new Phrase();

        p1 = new Paragraph("湖南民政社会救助保障对象审核确认表", firsetTitleFont);
        p1.setLeading(50);
        p1.setAlignment(Element.ALIGN_CENTER);
        doc.add(p1);


        p1 = new Paragraph(pdf.getCountyName()+" "+pdf.getStreeName(), textFont);
        p1.setLeading(50);
        //p1.setAlignment(Element.ALIGN_CENTER);



        doc.add(p1);

        p1 = new Paragraph(" ");
        p1.setLeading(10);
        doc.add(p1);






//        p1.setAlignment(Element.ALIGN_CENTER);





//        p1.setAlignment(Element.ALIGN_CENTER);


//        Chunk c2_1 = new Chunk(Calendar.getInstance().getTime() + "", textFont);












//        p1.setAlignment(Element.ALIGN_CENTER);























//        p1.setAlignment(Element.ALIGN_CENTER);



        Font font = new Font(bfChinese, 11, Font.BOLD);
        PdfPTable table = new PdfPTable(6);
        table.setTotalWidth(new float[]{80, 80, 80, 80, 80, 80});
        table.setLockedWidth(true);


        PdfPCell cell = new PdfPCell();

        for(int i = 0; i < 6; i++){
            switch (i){
                case 0: cell = new PdfPCell(new Phrase("户主姓名", font));
                    break;
                case 1: cell = new PdfPCell(new Phrase(pdf.getMasterName(), font));
                    break;
                case 2: cell = new PdfPCell(new Phrase("性别", font));
                    break;
                case 3: cell = new PdfPCell(new Phrase(pdf.getSex(), font));
                    break;
                case 4: cell = new PdfPCell(new Phrase("联系电话", font));
                    break;
                case 5: cell = new PdfPCell(new Phrase(pdf.getPhone(), font));
                    break;
            }
            cell.setMinimumHeight(25);
            cell.setUseAscender(true);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);
        }


        for(int i = 0; i < 4; i++){
            switch (i){
                case 0: cell = new PdfPCell(new Phrase("户主身份证", font));
                    break;
                case 1:
                    cell = cell = new PdfPCell(new Phrase(pdf.getMasterIdcard(), font));
                    cell.setColspan(2);
                    break;
                case 2: cell = cell = new PdfPCell(new Phrase("家庭住址", font));
                    break;
                case 3:
                    cell = new PdfPCell(new Phrase(pdf.getAddress(), font));
                    cell.setColspan(2);
                    break;
            }
            cell.setMinimumHeight(25);
            cell.setUseAscender(true);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        for(int i = 0; i < 6; i++){
            switch (i){
                case 0: cell = new PdfPCell(new Phrase("家庭成员数", font));
                    break;
                case 1: cell = new PdfPCell(new Phrase(pdf.getPersonNumber(), font));
                    break;
                case 2: cell = new PdfPCell(new Phrase("家庭年收入", font));
                    break;
                case 3: cell = new PdfPCell(new Phrase(pdf.getSrQue(), font));
                    break;
                case 4: cell = new PdfPCell(new Phrase("家庭年支出", font));
                    break;
                case 5: cell = new PdfPCell(new Phrase(pdf.getZcQue(), font));
                    break;
            }
            cell.setMinimumHeight(25);
            cell.setUseAscender(true);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        cell = new PdfPCell(new Phrase("申请理由", font));
        cell.setMinimumHeight(25);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(pdf.getReason(), font));
        cell.setMinimumHeight(25);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setColspan(5);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("审核通过的救助对象", font));
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setRowspan(pdf.getDetailList().size()+1);
        table.addCell(cell);

        table = createCell(table, new String[]{"姓名", "身份证号码", "家庭关系", "救助金额"}, 1, 4, -1);
        //String[] strings = pdf.getDetailList().stream().toArray(String[]::new);
        for (int i = 1; i < pdf.getDetailList().size()+1; i++) {
            table = createCell(table, new String[]{pdf.getDetailList().get(i-1).getName(),
                    pdf.getDetailList().get(i-1).getIdcard(),
                    pdf.getDetailList().get(i-1).getFamilyRelation(),
                    pdf.getDetailList().get(i-1).getSalaryNumber()}, 1, 4, -1);

        }
        cell = new PdfPCell(new Phrase("街道(乡镇)审核意见：", font));
        cell.setMinimumHeight(100);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setRowspan(2);
        cell.setColspan(2);
        cell.disableBorderSide(8);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(pdf.getStreeResult(), font));
        cell.setMinimumHeight(100);
        cell.setUseAscender(true);
        //cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setColspan(4);
        cell.disableBorderSide(6);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(pdf.getStreeDate(), font));
        cell.disableBorderSide(7);
        cell.setColspan(4);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("区(县)民政局审核意见：", font));
        cell.setMinimumHeight(100);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setRowspan(2);
        cell.setColspan(2);
        cell.disableBorderSide(8);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(pdf.getCityResult(), font));
        cell.setMinimumHeight(100);
        cell.setUseAscender(true);
        //cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setColspan(4);
        cell.disableBorderSide(6);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(pdf.getCityDate(), font));
        cell.disableBorderSide(5);
        cell.setColspan(4);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);

        doc.add(table);

        doc.close();
        return outPath;
    }


    private static PdfPTable createCell(PdfPTable table, String[] title, int row, int cols, int img_col_num) throws DocumentException, IOException {

        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font font = new Font(bfChinese, 11, Font.BOLD);
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < cols; j++) {
                PdfPCell cell = new PdfPCell();
                if (i == 0 && title != null) {
                    if (img_col_num == j) {
                        Image img = Image.getInstance(title[img_col_num]);
                        img.setBorderWidth(0);
                        img.scaleToFit(50, 70);
                        cell = new PdfPCell(img);
                        cell.setPadding(5);
                    } else {
                        cell = new PdfPCell(new Phrase(title[j], font));
                    }
                    if (table.getRows().size() == 0) {
                        cell.setBorderWidthTop(3);
                    }
                }
                if (row == 1 && cols == 1) {
                    cell.setBorderWidthTop(3);
                }









                if (j == 3) {
                    cell.setColspan(2);
                }
                cell.setMinimumHeight(40);
                cell.setUseAscender(true);
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                table.addCell(cell);
            }
        }
        return table;
    }


    public static void stringWaterMark(String inputFile, String waterMarkName) {
        try {
            String[] spe = DataUtil.separatePath(inputFile);
            String outputFile = spe[0] + "_WM." + spe[1];
            PdfReader reader = new PdfReader(inputFile);
            PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputFile));

            BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
            int total = reader.getNumberOfPages() + 1;
            PdfContentByte under;
            int j = waterMarkName.length();
            char c = 0;
            int rise = 0;

            for (int i = 1; i < total; i++) {
                rise = 400;
                under = stamper.getUnderContent(i);
                under.beginText();
                under.setFontAndSize(bfChinese, 30);
                under.setTextMatrix(200, 120);
                for (int k = 0; k < j; k++) {
                    under.setTextRise(rise);
                    c = waterMarkName.charAt(k);
                    under.showText(c + "");
                }

                under.endText();
            }
            stamper.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void imageWaterMark(String inputFile, String imageFile) {
        try {
            String[] spe = DataUtil.separatePath(inputFile);
            String outputFile = spe[0] + "_WM." + spe[1];
            PdfReader reader = new PdfReader(inputFile);
            PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputFile));
            int total = reader.getNumberOfPages() + 1;
            Image image = Image.getInstance(imageFile);
            image.setAbsolutePosition(-100, 0);
            image.scaleAbsolute(800, 1000);



            PdfGState gs = new PdfGState();
            gs.setFillOpacity(0.2f);
            PdfContentByte under;

            for (int i = 1; i < total; i++) {
                under = stamper.getUnderContent(i);
                under.beginText();

                under.addImage(image);
                under.setGState(gs);
            }
            stamper.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static String leftPad(String str, int i) {
        int addSpaceNo = i - str.length();
        String space = "";
        for (int k = 0; k < addSpaceNo; k++) {
            space = " " + space;
        }
        String result = space + str;
        return result;
    }


    public static String printBlank(int tmp) {
        String space = "";
        for (int m = 0; m < tmp; m++) {
            space = space + " ";
        }
        return space;
    }

    public static String[] transPdfToImgage(String pdfPath, String imagePath) {
        String[] imgs = null;
        File file = new File(pdfPath);
        try {
            PDDocument doc = Loader.loadPDF(file);
            PDFRenderer renderer = new PDFRenderer(doc);
            int pageCount = doc.getNumberOfPages();
            imgs = new String[pageCount];
            for(int i=0;i<pageCount;i++){
                String url = imagePath.replaceAll("\\.png",i + ".png");
                BufferedImage image = renderer.renderImageWithDPI(i, 296);
                //BufferedImage image = renderer.renderImage(i, 2.5f);
                ImageIO.write(image, "PNG", new File(url));
                imgs[i] = "[image]file://" + url + "[/image]";
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return imgs;
    }


    public static String createAuditConfirmList(String orderId, String businessType, AuditConfirmListDTO auditConfirmListDTO) throws Exception {

        String outPath =  System.getProperty("java.io.tmpdir")+orderId+".pdf";

        Rectangle rect = new Rectangle(PageSize.A4);

        Document doc = new Document(rect);

        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

        Font textFont = new Font(bfChinese, 11, Font.NORMAL);
        Font redTextFont = new Font(bfChinese, 11, Font.NORMAL);
        Font boldFont = new Font(bfChinese, 11, Font.BOLD);
        Font redBoldFont = new Font(bfChinese, 11, Font.BOLD);
        Font firsetTitleFont = new Font(bfChinese, 22, Font.BOLD);
        Font secondTitleFont = new Font(bfChinese, 15, Font.BOLD);
        Font underlineFont = new Font(bfChinese, 11, Font.UNDERLINE);

        PdfWriter.getInstance(doc, new FileOutputStream(new File(outPath)));

        doc.open();

        doc.newPage();

        Paragraph p1 = new Paragraph();

        Phrase ph1 = new Phrase();

        String title = "审核确认单";
        String saveMemberNum =  "";
        String baseMoney = "";
        String otherMoney = "";
        String reasonKey = "";
        String reason = "";
        String startDate = "救助开始年月";
        if(Constant.BusinessCode.DIBAO.equals(businessType)){
            title = "最低生活保障救助申请" + title;
            saveMemberNum = "保障人口数";
            baseMoney = "基本救助金";
            otherMoney = "分类救助金";
            reasonKey = "主要致困原因";
            reason = auditConfirmListDTO.getMainReason();
        }else if(Constant.BusinessCode.TEKUN.equals(businessType)){
            title = "特困人员救助供养申请" + title;
            saveMemberNum = "供养人口数";
            baseMoney = "基本生活费";
            otherMoney = "照料护理费";
            reasonKey = "申请原因";
            reason = auditConfirmListDTO.getReason();
        }else if(Constant.BusinessCode.LINSHI.equals(businessType)){
            title = "临时救助申请" + title;
            saveMemberNum = "救助人口数";
            baseMoney = "救助金额";
            reasonKey = "申请原因";
            startDate = "救助年月";
            reason = auditConfirmListDTO.getMainReason();
        }
        float cellHeight = 20f;

        Font font = new Font(bfChinese, 11, Font.BOLD);
        PdfPTable table = new PdfPTable(8);
        table.setTotalWidth(new float[]{60, 60, 60, 60, 60, 60,60,60});
        table.setLockedWidth(true);

        PdfPCell cell = new PdfPCell();

        cell = new PdfPCell(new Phrase(title, font));
        cell.setMinimumHeight(32);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setColspan(8);;
        table.addCell(cell);

        font = new Font(bfChinese, 9, Font.BOLD);
        cell = new PdfPCell(new Phrase("     家庭基本信息", font));
        cell.setMinimumHeight(25);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setColspan(6);;
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("", font));
        cell.setMinimumHeight(cellHeight);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setColspan(2);
        cell.setRowspan(6);;
        table.addCell(cell);

        textFont = new Font(bfChinese, 6, Font.NORMAL);
        for(int i = 0; i < 6; i++){
            switch (i){
                case 0: cell = new PdfPCell(new Phrase("户主姓名", textFont));
                    break;
                case 1: cell = new PdfPCell(new Phrase(auditConfirmListDTO.getName(), textFont));
                    break;
                case 2: cell = new PdfPCell(new Phrase("户主身份证", textFont));
                    break;
                case 3: cell = new PdfPCell(new Phrase(auditConfirmListDTO.getIdcard(), textFont));
                    break;
                case 4: cell = new PdfPCell(new Phrase("手机号码", textFont));
                    break;
                case 5: cell = new PdfPCell(new Phrase(auditConfirmListDTO.getPhone(), textFont));
                    break;
            }
            cell.setMinimumHeight(cellHeight);
            cell.setUseAscender(true);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        for(int i = 0; i < 6; i++){
            switch (i){
                case 0: cell = new PdfPCell(new Phrase("户籍类型", textFont));
                    break;
                case 1: cell = new PdfPCell(new Phrase(auditConfirmListDTO.getCensusType(), textFont));
                    break;
                case 2: cell = new PdfPCell(new Phrase("家庭人口数", textFont));
                    break;
                case 3: cell = new PdfPCell(new Phrase(auditConfirmListDTO.getFamilyNumber(), textFont));
                    break;
                case 4: cell = new PdfPCell(new Phrase(saveMemberNum, textFont));
                    break;
                case 5: cell = new PdfPCell(new Phrase(auditConfirmListDTO.getSaveMemberNumber(), textFont));
                    break;
            }
            cell.setMinimumHeight(cellHeight);
            cell.setUseAscender(true);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        for(int i = 0; i < 6; i++){
            switch (i){
                case 0: cell = new PdfPCell(new Phrase(reasonKey, textFont));
                    break;
                case 1: cell = new PdfPCell(new Phrase(reason, textFont));
                    break;
                case 2: cell = new PdfPCell(new Phrase("申请日期", textFont));
                    break;
                case 3: cell = new PdfPCell(new Phrase(auditConfirmListDTO.getCommitDate(), textFont));
                    break;
                case 4: cell = new PdfPCell(new Phrase(startDate, textFont));
                    break;
                case 5: cell = new PdfPCell(new Phrase(auditConfirmListDTO.getStartDate(), textFont));
                    break;
            }
            cell.setMinimumHeight(cellHeight);
            cell.setUseAscender(true);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        cell = new PdfPCell(new Phrase("户籍地址", textFont));
        cell.setMinimumHeight(cellHeight);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(auditConfirmListDTO.getCensusPlace(), textFont));
        cell.setMinimumHeight(cellHeight);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setColspan(5);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("居住地址", textFont));
        cell.setMinimumHeight(cellHeight);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(auditConfirmListDTO.getAddress(), textFont));
        cell.setMinimumHeight(cellHeight);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setColspan(5);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("     家庭保障信息及待遇信息", font));
        cell.setMinimumHeight(cellHeight);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setColspan(6);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("家庭信息查询二维码", textFont));
        cell.setMinimumHeight(cellHeight);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setColspan(2);
        table.addCell(cell);


        for(int i = 0; i <8; i++){
            switch (i){
                case 0: cell = new PdfPCell(new Phrase("姓名", textFont));
                    break;
                case 1: cell = new PdfPCell(new Phrase("身份证号", textFont));
                    break;
                case 2: cell = new PdfPCell(new Phrase("与户主关系", textFont));
                    break;
                case 3: cell = new PdfPCell(new Phrase("健康状况", textFont));
                    break;
                case 4: cell = new PdfPCell(new Phrase("残疾类型", textFont));
                    break;
                case 5: cell = new PdfPCell(new Phrase("残疾等级", textFont));
                    break;
                case 6: if(!Constant.BusinessCode.LINSHI.equals(businessType)){
                           cell = new PdfPCell(new Phrase(baseMoney, textFont));
                         }else {
                           cell = new PdfPCell(new Phrase("救助金额", textFont));
                           cell.setColspan(2);
                         }
                         break;
                case 7: if(!Constant.BusinessCode.LINSHI.equals(businessType)){
                         cell = new PdfPCell(new Phrase(otherMoney, textFont));
                        }else {
                         cell = null;
                       }
                       break;
            }
            if(null!=cell){
                cell.setMinimumHeight(cellHeight);
                cell.setUseAscender(true);
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                table.addCell(cell);
            }

        }

        List<ConfirmListMemberDTO> memberList = auditConfirmListDTO.getMemberList();
        for(ConfirmListMemberDTO memberDTO : memberList){
            for(int i = 0; i < 8; i++){
                switch (i){
                    case 0: cell = new PdfPCell(new Phrase(memberDTO.getName(), textFont));
                        break;
                    case 1: cell = new PdfPCell(new Phrase(memberDTO.getIdcard(), textFont));
                        break;
                    case 2: cell = new PdfPCell(new Phrase(memberDTO.getFamilyRelation(), textFont));
                        break;
                    case 3: cell = new PdfPCell(new Phrase(memberDTO.getHealthState(), textFont));
                        break;
                    case 4: cell = new PdfPCell(new Phrase(memberDTO.getDisabilityType(), textFont));
                        break;
                    case 5: cell = new PdfPCell(new Phrase(memberDTO.getDisabilityLevel(), textFont));
                        break;
                    case 6: if(!Constant.BusinessCode.LINSHI.equals(businessType)){
                               cell = new PdfPCell(new Phrase(memberDTO.getBaseSalary(), textFont));
                            }else{
                               cell = new PdfPCell(new Phrase(memberDTO.getBaseSalary(), textFont));
                               cell.setColspan(2);
                          }
                        break;
                    case 7: if(!Constant.BusinessCode.LINSHI.equals(businessType)){
                        cell = new PdfPCell(new Phrase(memberDTO.getOtherSalary(), textFont));
                    }else{
                        cell = null;
                    }
                        break;
                }
                if(null!=cell){
                    cell.setMinimumHeight(cellHeight);
                    cell.setUseAscender(true);
                    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                    table.addCell(cell);
                }
            }
        }

        cell = new PdfPCell(new Phrase("家庭救助金额", textFont));
        cell.setMinimumHeight(cellHeight);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(auditConfirmListDTO.getSalvMoney(), textFont));
        cell.setMinimumHeight(cellHeight);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setColspan(7);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("审核人", textFont));
        cell.setMinimumHeight(cellHeight);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(auditConfirmListDTO.getCheckPeople(), textFont));
        cell.setMinimumHeight(cellHeight);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setColspan(3);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("审核时间", textFont));
        cell.setMinimumHeight(cellHeight);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(auditConfirmListDTO.getCheckDate(), textFont));
        cell.setMinimumHeight(cellHeight);
        cell.setUseAscender(true);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setColspan(3);
        table.addCell(cell);
        doc.add(table);
        doc.close();
        return outPath;
    }

    public static void drawQrcode(String url,String path){
        File f = new File(path);
    }

    public static String drawImageOnPdf(String inputFile, String imageFile) {
        String outputFile = "";
        PdfStamper stamper = null;
        try {
            PdfReader reader = new PdfReader(inputFile);
            String[] spe = DataUtil.separatePath(inputFile);
            outputFile = spe[0] + "_jz." + spe[1];
            stamper = new PdfStamper(reader, new FileOutputStream(outputFile));
            Image image = Image.getInstance(imageFile);
            image.setAbsolutePosition(418, 650);
            image.scaleAbsolute(119, 123);
            PdfGState gs = new PdfGState();
            gs.setFillOpacity(1f);
            PdfContentByte under;

            under = stamper.getUnderContent(1);
            under.beginText();

            under.addImage(image);
            under.setGState(gs);
            stamper.close();
            reader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (stamper != null) {
                try {
                    stamper.close();
                } catch (DocumentException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return outputFile;
    }

    public static String generateAuditConfirmList(String orderId, String businessType, AuditConfirmListDTO auditConfirmListDTO) throws Exception {

        String pdfPath = createAuditConfirmList(orderId,businessType,auditConfirmListDTO);


        String qrcodePath =  System.getProperty("java.io.tmpdir")+orderId+"_qrcode"+".png";
        drawQrcode("https://www.baidu.com",qrcodePath);

        String confirmPdfPath = drawImageOnPdf(pdfPath,qrcodePath);

        File file = new File(pdfPath);
        if(file.exists()){
            file.delete();
        }
        file = new File(qrcodePath);
        if(file.exists()){
            file.delete();
        }
        return confirmPdfPath;
    }
    public static void main(String[] args) {
        drawImageOnPdf("E:\\f425073500b947a7919aeb8f14d6a379.pdf","E://qrcode.png");
//        File f = new File("E://qrcode.png");
//        QrCodeUtil.generate("https://www.baidu.com",300,300,f);
    }
}
